<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>报警列表</title>

    <link href="../../resource/css/bootstrap.min.css?v=3.3.5" rel="stylesheet"
          th:href="@{/resource/css/bootstrap.min.css(v=3.3.5)}"/>
    <link href="../../resource/css/font-awesome.min.css?v=4.4.0" rel="stylesheet"
          th:href="@{/resource/css/font-awesome.min.css(v=4.4.0)}"/>
    <!-- Morris -->
    <link href="http://cdn.viptool.cn/lib/morris.js/0.4.3/morris.css" rel="stylesheet">
    <link href="../../resource/css/animate.min.css" rel="stylesheet" th:href="@{/resource/css/animate.min.css}"/>

    <link href="../../resource/css/style.min.css?v=4.0.0" rel="stylesheet"
          th:href="@{/resource/css/style.min.css(v=4.0.0)}"/>
    <link href="../../resource/hotui/css/hotui.style.override.css"
          th:href="@{/resource/hotui/css/hotui.style.override.css}" rel="stylesheet"/>
    <link href="../../resource/hotui/js/plugins/datetimepick/css/daterangepicker.css"
          th:href="@{/resource/hotui/js/plugins/datetimepick/css/daterangepicker.css}" rel="stylesheet"/>
    <style type="text/css">
        .hr-line-dashed {
            margin: 10px 0;
            height: 1px;
            border-top: 1px dashed #e7eaec;
            background-color: #fff;
            color: #fff;
        }
    </style>
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content tooltip-demo">
    <!--search-->
    <form role="form" id="searchForm" class="search-panel" method="get" th:object="${condition}">
        <input type="hidden" th:value="${pageIndex}" name="pageIndex"/>
        <input type="hidden" th:value="*{alarmStatus}" name="alarmStatus"/>
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <div class="form-inline">
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="userKey">姓名：</label>
                                <input type="text" class="form-control input-sm mb10" id="userKey" th:value="*{userKey}"
                                       name="userKey" placeholder="账户/姓名" style="width: 156px;"/>
                            </div>
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="createTimePick">创建时间：</label>
                                <input readonly type="text" class="form-control input-sm mb10 data-range-pick"
                                       id="createTimePick" name="createTimePick" start-element="#beginTime"
                                       end-element="#endTime" placeholder="开始时间-结束时间" style="width: 377px;"/>
                                <input type="hidden" th:value="*{beginTime}" id="beginTime" name="beginTime"/>
                                <input type="hidden" th:value="*{endTime}" id="endTime" name="endTime"/>
                            </div>
                            <div class="form-group m-r-sm">
                                <button type="button" onclick="listHandler.search(1)"
                                        class="btn btn-primary btn-sm m-b-none searchBtn">筛选
                                </button>
                                <button type="button" onclick="listHandler.searchAll()"
                                        class="btn btn-primary btn-sm m-b-none">显示全部
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <!--search-->
    <!--list-->
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins m-b-none">
                <div class="tabs-container">
                    <ul class="nav nav-tabs">
                        <li class="active" th:class="${condition.alarmStatus==-1?'active':''}">
                            <a th:href="@{/msg/alarm/list}" href="#">全部</a>
                        </li>
                        <li th:class="${alarmStatus.code==condition.alarmStatus?'active':''}"
                            th:each="alarmStatus:${alarmStatuses}">
                            <a th:href="@{/msg/alarm/list(alarmStatus=${alarmStatus.code})}"
                               th:text="${alarmStatus.desc}" href="#">全部</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active">
                            <div class="panel-body">
                                <table class="table table-bordered table-hover table-center">
                                    <thead>
                                    <tr>
                                        <th>所属用户</th>
                                        <th>报警类型</th>
                                        <th>首次报警时间</th>
                                        <th>最新报警时间</th>
                                        <th>状态</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>

                                    <tr th:each="item:${list}">
                                        <td th:text="${item.userName}"></td>
                                        <td th:text="${item.alarmType.desc}"></td>
                                        <td th:text="${#temporals.format(item.createTime,'yyyy-MM-dd HH:mm:ss')}"></td>
                                        <td th:text="${#temporals.format(item.updateTime,'yyyy-MM-dd HH:mm:ss')}"></td>
                                        <td th:text="${item.alarmStatus.desc}"></td>
                                        <td>
                                            <th:block th:switch="${item.alarmStatus.code}">
                                                <a th:case="0"
                                                   th:href="|javascript:alarmHandler.onRoadModal(${item.groupId})|"
                                                   href="javascript:alarmHandler.onRoadModal(1)">出警</a>
                                                <a th:case="1"
                                                   th:href="|javascript:alarmHandler.handle(${item.groupId})|"
                                                   href="javascript:alarmHandler.handle(1)">设为已处理</a>
                                                <a th:case="2"
                                                   th:href="|javascript:alarmHandler.submitModal(${item.groupId})|"
                                                   href="javascript:alarmHandler.submitModal(1)">提交工单</a>
                                            </th:block>
                                            <a th:if="${item.alarmStatus.code==0}"
                                               th:href="|javascript:alarmHandler.ignore(${item.groupId})|"
                                               href="javascript:alarmHandler.ignore(1)">忽略</a>
                                            <a th:if="${item.alarmStatus.code==3}"
                                               th:href="|javascript:alarmHandler.workOrder(${item.groupId})|"
                                               href="javascript:alarmHandler.workOrder(1)">查看工单</a>
                                            <a th:href="|javascript:alarmHandler.optList(${item.groupId})|"
                                               href="javascript:alarmHandler.optList(1)">操作记录</a>
                                            <a th:href="|javascript:alarmHandler.msgList(${item.groupId})|"
                                               href="javascript:alarmHandler.msgList(1)">消息列表</a>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                                <p style="float: left; margin: 20px 0;">
                                    共<span th:text="${totalRecords}"></span>条记录，当前第<span
                                        th:text="${pageIndex}"></span>/<span
                                        th:text="${totalPages==0?1:totalPages}"></span>，每页20条记录
                                </p>
                                <ul style="float: right;" class="pagination pagination-split">
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="onRoad_modal" style="display: none;">
    <input type="hidden" id="onRoad_group_id"/>
    <div class="form-horizontal" style="width: 479px;">
        <div class="form-group form-inline">
            <label class="col-sm-3 control-label">*处理人姓名：</label>
            <div class="col-sm-9">
                <input type="text" id="onRoad_name" class="form-control input-sm input-s"
                       placeholder="处理人姓名"/>
            </div>
        </div>
        <div class="form-group form-inline">
            <label class="col-sm-3 control-label">*处理人手机：</label>
            <div class="col-sm-9">
                <input type="text" id="onRoad_mobile"
                       class="form-control input-sm input-s" placeholder="处理人手机"/>
            </div>
        </div>
    </div>
</div>

<div id="submit_modal" style="display: none;">
    <input type="hidden" id="submit_group_id"/>
    <div class="form-horizontal" style="width: 479px;">
        <div class="form-group form-inline">
            <label class="col-sm-3 control-label">*处理人姓名：</label>
            <div class="col-sm-9">
                <input type="text" id="submit_name" class="form-control input-sm input-s"
                       placeholder="处理人姓名"/>
            </div>
        </div>
        <div class="form-group form-inline">
            <label class="col-sm-3 control-label">*处理人手机：</label>
            <div class="col-sm-9">
                <input type="text" id="submit_mobile"
                       class="form-control input-sm input-s" placeholder="处理人手机"/>
            </div>
        </div>
        <div class="form-group form-inline">
            <label class="col-sm-3 control-label">*处理地点：</label>
            <div class="col-sm-9">
                <input type="text" id="submit_addr" style="width: 100%"
                       class="form-control input-sm input-s" placeholder="处理地点"/>
            </div>
        </div>
        <div class="form-group form-inline">
            <label class="col-sm-3 control-label">*事发原因：</label>
            <div class="col-sm-9">
                <input type="text" id="submit_reason" style="width: 100%"
                       class="form-control input-sm input-s" placeholder="事发原因"/>
            </div>
        </div>
        <div class="form-group form-inline">
            <label class="col-sm-3 control-label">*备注：</label>
            <div class="col-sm-9">
                <input type="text" id="submit_remark" style="width: 100%"
                       class="form-control input-sm input-s" placeholder="备注"/>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="work_order_detail">
    <div class="form-horizontal" style="width: 479px;">
        <div class="form-group form-inline">
            <label class="col-sm-3 control-label">处理人姓名：</label>
            <div class="col-sm-9">
                <input type="text" class="form-control input-sm input-s" readonly value="{{name}}"
                       placeholder="处理人姓名"/>
            </div>
        </div>
        <div class="form-group form-inline">
            <label class="col-sm-3 control-label">处理人手机：</label>
            <div class="col-sm-9">
                <input type="text" readonly value="{{mobile}}"
                       class="form-control input-sm input-s" placeholder="处理人手机"/>
            </div>
        </div>
        <div class="form-group form-inline">
            <label class="col-sm-3 control-label">处理地点：</label>
            <div class="col-sm-9">
                <input type="text" style="width: 100%" readonly value="{{address}}"
                       class="form-control input-sm input-s" placeholder="处理地点"/>
            </div>
        </div>
        <div class="form-group form-inline">
            <label class="col-sm-3 control-label">事发原因：</label>
            <div class="col-sm-9">
                <textarea rows="3" style="width: 100%" readonly class="form-control">{{reason}}</textarea>
            </div>
        </div>
        <div class="form-group form-inline">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-9">
                <textarea rows="3" style="width: 100%" readonly class="form-control">{{remark}}</textarea>
            </div>
        </div>
    </div>
</script>

<!--基础框架js-->
<script src="../../resource/js/jquery.min.js?v=2.1.4" th:src="@{/resource/js/jquery.min.js(v=2.1.4)}"></script>
<script src="../../resource/js/bootstrap.min.js?v=3.3.5" th:src="@{/resource/js/bootstrap.min.js(v=3.3.5)}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js(123123)}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js"></script>

<script src="../../resource/hotui/js/content.min.js" th:src="@{/resource/hotui/js/content.min.js}"></script>
<script src="../../resource/lib/moment.min.js" th:src="@{/resource/lib/moment.min.js}"></script>
<script src="../../resource/hotui/js/plugins/datetimepick/js/daterangepicker.js"
        th:src="@{/resource/hotui/js/plugins/datetimepick/js/daterangepicker.js}"></script>

<script type="text/javascript" th:inline="javascript">
    const pageIndex = /*[[${pageIndex}]]*/  1;
    const totalPages = /*[[${totalPages}]]*/  1;
    const pageUri = /*[[@{/msg/alarm/list}]]*/  "";
    const apiUri = /*[[@{/msg/alarm}]]*/  "";
</script>
<script>
    var onRoadModal = $("#onRoad_modal").modal("处理人员信息", function () {
        let name = $.trim($("#onRoad_name").val());
        let mobile = $.trim($("#onRoad_mobile").val());
        let groupId = $("#onRoad_group_id").val();

        alarmHandler.onRoad(groupId, name, mobile);
    });

    var submitModal = $("#submit_modal").modal('提交工单', function () {
        alarmHandler.submit();
    });

    $(function () {
        //初始化分页
        var pageinate = new hot.paging(".pagination", pageIndex, totalPages, 7);

        pageinate.init(function (p) {
            listHandler.search(p);
        });
    });

    var listHandler = {
        search: function (pageIndex) {
            $("input[name=pageIndex]").val(pageIndex);
            $("#searchForm").submit();
        },
        searchAll: function () {
            window.location.href = pageUri + "?userId=" + $("#userId").val();
        }
    };

    var alarmHandler = {
        onRoadModal: function (groupId) {
            onRoadModal.show(function () {
                $("#onRoad_group_id").val(groupId);
            })
        },
        onRoad: function (groupId, name, mobile) {
            hot.ajax(apiUri + "/onRoad", {
                groupId: groupId,
                policeName: name,
                policeMobile: mobile
            }, function (apiResult) {
                if (apiResult.resultCode === 2000) {
                    hot.tip.success("操作成功", function () {
                        window.location.reload();
                    })
                } else {
                    hot.tip.error("操作失败--" + apiResult.resultMsg);
                }
            }, function () {
            }, "post");
        },
        handle: function (groupId) {
            hot.ajax(apiUri + "/handle", {
                groupId: groupId
            }, function (apiResult) {
                if (apiResult.resultCode === 2000) {
                    hot.tip.success("操作成功", function () {
                        window.location.reload();
                    })
                } else {
                    hot.tip.error("操作失败--" + apiResult.resultMsg);
                }
            }, function () {
            }, "post");
        },
        ignore: function (groupId) {
            hot.confirm("确定忽略该次警报？", function () {
                layer.prompt({
                    title: '备注',
                    formType: 2
                }, function (text, index) {
                    layer.close(index);
                    hot.ajax(apiUri + "/ignore", {
                        groupId: groupId,
                        remark: text
                    }, function (apiResult) {
                        if (apiResult.resultCode === 2000) {
                            hot.tip.success("操作成功", function () {
                                window.location.reload();
                            })
                        } else {
                            hot.tip.error("操作失败--" + apiResult.resultMsg);
                        }
                    }, function () {
                    }, "post");
                })
            });
        },
        submitModal: function (groupId) {
            submitModal.show(function () {
                $("#submit_group_id").val(groupId);

                hot.ajax(apiUri + "/policeInfo", {
                    groupId: groupId
                }, function (apiResult) {
                    if (apiResult.resultCode === 2000) {
                        $("#submit_name").val(apiResult.data.policeName);
                        $("#submit_mobile").val(apiResult.data.policeMobile);
                    }
                }, function () {
                }, "get");
            });
        },
        submit: function () {
            let groupId = $("#submit_group_id").val();
            let handleAddr = $.trim($("#submit_addr").val());
            let reason = $.trim($("#submit_reason").val());
            let policeName = $.trim($("#submit_name").val());
            let policeMobile = $.trim($("#submit_mobile").val());
            let remark = $.trim($("#submit_remark").val());

            let requestData = {
                groupId: groupId,
                handleAddr: handleAddr,
                reason: reason,
                policeName: policeName,
                policeMobile: policeMobile,
                remark: remark
            };

            hot.ajax(apiUri + "/submit", requestData, function (apiResult) {
                if (apiResult.resultCode === 2000) {
                    hot.tip.success("操作成功", function () {
                        window.location.reload();
                    })
                } else {
                    hot.tip.error("操作失败--" + apiResult.resultMsg);
                }
            }, function () {
            }, "post");
        },
        workOrder: function (groupId) {
            hot.ajax(apiUri + "/workOrder", {
                groupId: groupId
            }, function (apiResult) {
                if (apiResult.resultCode === 2000) {
                    let data = apiResult.data;
                    let detail = $("#work_order_detail").html();
                    detail = detail.replace('{{name}}', data.policeName);
                    detail = detail.replace('{{mobile}}', data.policeMobile);
                    detail = detail.replace('{{address}}', data.handleAddr);
                    detail = detail.replace('{{reason}}', data.reason);
                    detail = detail.replace('{{remark}}', data.remark);

                    layer.open({
                        content: detail,
                        area: ['600px', '500px'],
                        yes: function (index, layero) {
                            layer.close(index);
                        }
                    });
                }
            }, function () {
            }, "get");
        },
        optList: function (groupId) {
            let url = apiUri + "/optList?groupId=" + groupId;

            hot.iframeModal(url, '800px', '500px', '操作记录');
        },
        msgList: function (groupId) {
            let url = apiUri + "/msgList?groupId=" + groupId;

            hot.iframeModal(url, '800px', '500px', '消息列表');
        }
    }
</script>
</body>
</html>
